import {
  deleteViolationRecord,
  getAllViolationType,
  getErrorAppealSolutionList,
  getViolationImage, sendFeedbackInformation
} from "../../../../api/data";

export default {
  name: "complaint-component",
  data() {
    return {
      name: '',
      modal1: false,
      modal2: false,
      imgSrc: '',
      text: '',
      selected: '',
      queryData: {
        actionType: '0',
        violateType: '7',
        account: '',
        page:'1',
        limit:'10'
      },
      actionType: [
        {
          id: 0,
          type: "未处理",
        },
        {
          id: 1,
          type: "已处理",
        }
      ],
      violateType: [],
      columns1: [
        {
          title: '申诉编号',
          key: 'ueappealId'
        },
        {
          title: '用户账号',
          key: 'account'
        },
        {
          title: '违规行为',
          key: 'udvtypeName'
        },
        {
          title: '用户反馈',
          key: 'ueappealDecribe',
          align: "center"
        },
        {
          title: '状态',
          key: 'ueappealStatus',
          align: "center"
        },
        {
          title: '操作',
          key: 'action',
          slot: 'action',
          align: 'center'
        }
      ],
      data1: []
    }
  },
  methods: {
    changePage(pageNumber) {
      this.queryData.page = pageNumber
      this.queryList()
    },
    changeSize(pageSize) {
      this.queryData.limit = pageSize
    },
    detail(index) {
      this.selected=index
      getViolationImage(this.data1[index].udvrecordId).then(res=>{
        this.imgSrc = 'data:image/jpeg;base64,' + res.data.obj
      }).catch(err=>{
        alert(err.message())
      })
      this.modal1 = true
    },

    getAllViolationType_(){
      getAllViolationType().then(res=>{
        this.violateType=res.data.obj
      }).catch(err=>{
        alert(err.message())
      })
    },
    ok() {
      deleteViolationRecord(this.data1[index].udvrecordId).then(res=>{
        if(res.data.code==200){
          this.$Message.info("删除违规记录成功");
        }
      }).catch(err=>{
        alert(err.message())
      })
    },
    query() {
      getErrorAppealSolutionList(this.queryData).then(res =>{
          res.data.obj.forEach(item =>{
            if (item.ueappealStatus==1){
              item.ueappealStatus='已处理'
            }else{
              item.ueappealStatus='未处理'
            }
          })
        this.data1=res.data.obj
      }).catch(err =>{
        alert(err.message())
      })
    },
    submit(){
      sendFeedbackInformation(this.data1[this.selected].ueappealId,this.text).then(res=>{
        if(res.data.code==200){
          this.$Message.info("反馈信息添加成功");
        }
      }).catch(err =>{
        alert(err.message())
      })
      this.query()
    },
    click() {

    },
    reset() {

    },
    send(index) {
      this.selected=index
      this.modal2 = true
    },
    cancel(){
      this.modal1 = false
      this.modal2 = true

    },
    reback() {
      this.modal1 = false;
      this.modal2 = true;
    }
  },
  mounted() {
    this.getAllViolationType_()
  }
}
